package com.wanban.downloader.db

import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.wanban.downloader.db.room.M3U8Converters
import com.wanban.downloader.db.room.MapConverters
import com.wanban.downloader.model.DownloadType
import com.wanban.downloader.model.M3U8
import com.wanban.downloader.model.Status
import java.io.Serializable

@Entity
@TypeConverters(M3U8Converters::class, MapConverters::class)
class DownloadEntity: Serializable {
    @PrimaryKey(autoGenerate = false)
    lateinit var url: String
    lateinit var videoName: String
    var coverUrl: String? = null
    // 视频id
    var videoId = 0L
    @Status
    // 下载状态
    var state = Status.IDLE
    // 下载的剧集数
    var episode = 0
    // 下载百分比
    var percent = 0f
    // 下载用的线路
    var sourceId = 0
    // 视频分类
    var category = 0
    // 重试次数
    var retryTime = 0
    // 观看时间
    var watchTime = 0L
    // 下载大小
    var contentLength = 0L
    // 文件路径
    var filePath: String? = null
    // 出错消息
    var errorMsg: String? = null
    // 原始url，解析前的
    var fromUrl: String? = null
    // 当前剧集的名字
    var episodeName: String? = null
    // 封面路径
    var coverFilePath: String? = null
    // m3u8具体信息
    var m3u8: M3U8? = null
    // header
    var header: HashMap<String, String>? = null
    // 文件目录  /Data/Android/xxx/files/Wanban/${fileName}
    var fileDirPath: String? = null

    // 新增参数
    @Ignore
    var downloadType: Int = DownloadType.SELF

    @Ignore
    var createTime = 0L

    /**
     * 以下参数不参与数据库存储
     */
    @Ignore
    var speed = 0L
    @Ignore
    var episodeCount = 0
    @Ignore
    var startTaskTime = 0L
    @Ignore
    var isSelected = false
    @Ignore
    var isUpdateWatchTime = false
    // 是否因为网络导致出错
    @Ignore
    var isNetworkError = false

    fun getFileName(): String {
        return videoName + "_" + videoId + "_" +sourceId + "_" + episode
    }
}
